let data1 = [];

function getDay (day) {
  var today = new Date();
  var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
  today.setTime(targetday_milliseconds);
  var tYear = today.getFullYear();
  var tMonth = today.getMonth();
  var tDate = today.getDate();
  tMonth = doHandleMonth(tMonth + 1);
  tDate = doHandleMonth(tDate);
  // return tYear+"-"+tMonth+"-"+tDate; //年月日
  return tMonth + "-" + tDate; //月日
}
function doHandleMonth (month) {
  var m = month;
  if (month.toString().length == 1) {
    m = "0" + month;
  }
  return m;
}

function dsdd (e) {  //拼接
  data1.splice(0);//请控之前的数据
  for (let i = 0; i < e; i++) {
    data1.push(getDay(-i));//-i 代表之前  i代表将来
  }
}

function util () {
  dsdd(30)
  return data1.reverse()
}
dsdd(30) //前30
console.log(data1.reverse())
const data = data1.reverse()
const data2 = data1.reverse()

let a = [{ date: "05-13", total: 1 }, { date: "05-14", total: 2 }, { date: "05-16", total: 2 }]

const map1 = new Map();
for (let i = 0; i < a.length; i++) {
  map1.set(a[i].date, a[i].total)
}
console.log(map1);
for (let i = 0; i < data.length; i++) {
  if (map1.get(data[i])) {
    data[i] = map1.get(data[i])
  } else {
    data[i] = 0
  }
}
console.log(data);
// let b = []
// for (let i = 0; i < data.length; i++) {
//   for (let j = 0; j < a.length; j++) {
//     if (a[j].date == data[i]) {
//       data2[i] = a[j].total
//     }
//     else if (data[i] == 1) {
//       data[i] = 1
//     }
//     else {
//       data2[i] = 0
//     }
//   }


// }
// console.log(data2);

export { util }